package com.ohuang.myapp.provider;

import com.ohuang.myapp.ResourceTable;
import com.ohuang.myapp.bean.TieBa;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public class ViewProvider extends PageSliderProvider {

    Context context;

    public ViewProvider(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_fg_list, null, false);
        ComponentContainer.LayoutConfig layoutConfig=new ComponentContainer.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_PARENT,
                ComponentContainer.LayoutConfig.MATCH_PARENT
        );
        componentContainer.addComponent(component,layoutConfig);
        ListContainer listContainer= (ListContainer) component.findComponentById(ResourceTable.Id_listview);
        List<TieBa> list=new ArrayList<>();
        for (int j=0;j<100;j++){
            list.add(new TieBa("这是第"+j+"条内容"));
        }
        ListProvider2 listProvider=new ListProvider2(list,context);
        listContainer.setItemProvider(listProvider);




        return component;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return false;
    }
}
